const mongoose = require('./db')
//  注册&登录表
const loginSchame = new mongoose.Schema({
    user: {
        type: String,
        required: true,// 必填
        unique: true, //唯一
    }, // 登录账号
    password: String, // 登录密码
    realName: String, // 真实姓名
    sex: String, // 性别
    nickName: String, // 昵称
    avater: String,// 头像
    Email: String, // 邮箱
    phone: String, // 手机号
    desc: String, //专业知识
    city: String, // 城市
    postalCode: String, //邮编
    address: String, //详细地址
    my: String,// 简介
    role: String, //角色
})

// 用户表的好友列表
const friendSchema = new mongoose.Schema({
    myid: mongoose.Types.ObjectId,
    friendid: mongoose.Types.ObjectId,
    date: {
        type: String,
        default: new Date().toLocaleString()
    },
})

let messageSchema = new mongoose.Schema({
    myid: mongoose.Types.ObjectId,
    toid: mongoose.Types.ObjectId,
    context: String,
    emoji: String,
    imgUrl: String,
    date: {
        type: String,
        default: new Date().toLocaleString()
    },
    img: String,
    voice: String
})

const loginMdel = mongoose.model('login', loginSchame, 'login')
const messagemodel = mongoose.model('message', messageSchema, 'message')
const friendmodel = mongoose.model('friend', friendSchema, 'friend')

// friendmodel.create({
//     myid: "654dc6235f7e2ddb929c4028",
//     friendid: "65542e0d5de92d344c15018f"
// })

module.exports = {
    messagemodel,
    loginMdel,
    friendmodel
}

// messagemodel.create({
//     myid: "654dc6235f7e2ddb929c4028",
//     toid: "65542e0d5de92d344c15018f",
//     context: "你好",
//     imgUrl: '王鸿权.jpg',
//     date: new Date().toLocaleString(),
//     img: 'http://localhost:3000/upload/20171007200848_VfWE5.jpeg'
// })